package com.wen.common.enums;

import java.util.Objects;

/**
 * 系统服务枚举类
 * <p>
 *
 * @author liwen <devinlive@163.com>
 * @version 1.0
 * @since 2022/12/16 21:09
 */
public enum ServiceEnum {

    VSFTPD("vsftpd.service", "FTP服务"),

    SSHD("sshd.service", "SSHD服务"),

    TEST1("sshd.service", "测试服务1", "restart"),

    TEST2("sshd.service", "测试服务2", "restart", "enable");

    private final String serviceName;
    private final String title;
    private String state;
    private final String daemon;

    private static final String DAEMON_DEFAULT = "disable";

    private ServiceEnum(String serviceName, String title) {
        this.serviceName = serviceName;
        this.title = title;
        this.daemon = DAEMON_DEFAULT;
    }

    private ServiceEnum(String serviceName, String title, String state) {
        this.serviceName = serviceName;
        this.title = title;
        this.state = state;
        this.daemon = DAEMON_DEFAULT;
    }

    private ServiceEnum(String serviceName, String title, String state, String daemon) {
        this.serviceName = serviceName;
        this.title = title;
        this.state = state;
        this.daemon = daemon;
    }

    /**
     * 通过服务名获取枚举类型
     */
    public static ServiceEnum getInstance(String serviceName) {
        ServiceEnum[] services = ServiceEnum.values();
        for (ServiceEnum service : services) {
            if (Objects.equals(service.serviceName, serviceName)) {
                return service;
            }
        }
        return null;
    }

    public String getServiceName() {
        return serviceName;
    }

    public String getTitle() {
        return title;
    }

    public String getState() {
        return state;
    }

    public String getDaemon() {
        return daemon;
    }

    @Override
    public String toString() {
        return "ServiceEnum{" +
                "serviceName='" + serviceName + '\'' +
                ", title='" + title + '\'' +
                ", state='" + state + '\'' +
                ", daemon='" + daemon + '\'' +
                '}';
    }
}
